import { Vector2D } from '../utils/Vector2D';

export class UIRenderer {
    constructor(private ctx: CanvasRenderingContext2D) {}

    public renderScore(score: number): void {
        this.ctx.fillStyle = '#fff';
        this.ctx.font = '24px Arial';
        this.ctx.textAlign = 'left';
        this.ctx.fillText(`分数: ${score}`, 20, 40);
    }

    public renderGameOver(score: number, canvas: HTMLCanvasElement): { restartButton: { buttonX: number; buttonY: number; buttonWidth: number; buttonHeight: number }; menuButton: { buttonX: number; buttonY: number; buttonWidth: number; buttonHeight: number } } {
        this.ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
        this.ctx.fillRect(0, 0, canvas.width, canvas.height);

        this.ctx.fillStyle = '#fff';
        this.ctx.font = '48px Arial';
        this.ctx.textAlign = 'center';
        this.ctx.fillText('游戏结束', canvas.width / 2, canvas.height / 2);
        this.ctx.font = '24px Arial';
        this.ctx.fillText(
            `最终分数: ${score}`,
            canvas.width / 2,
            canvas.height / 2 + 50
        );

        const buttonWidth = 200;
        const buttonHeight = 50;
        const buttonSpacing = 20;

        // 重新开始按钮
        const restartButtonX = canvas.width / 2 - buttonWidth / 2;
        const restartButtonY = canvas.height / 2 + 100;

        this.ctx.fillStyle = '#4CAF50';
        this.ctx.fillRect(restartButtonX, restartButtonY, buttonWidth, buttonHeight);
        
        this.ctx.fillStyle = '#fff';
        this.ctx.font = '24px Arial';
        this.ctx.fillText('重新开始', canvas.width / 2, restartButtonY + buttonHeight / 2 + 8);

        // 返回主菜单按钮
        const menuButtonX = canvas.width / 2 - buttonWidth / 2;
        const menuButtonY = restartButtonY + buttonHeight + buttonSpacing;

        this.ctx.fillStyle = '#2196F3';
        this.ctx.fillRect(menuButtonX, menuButtonY, buttonWidth, buttonHeight);
        
        this.ctx.fillStyle = '#fff';
        this.ctx.font = '24px Arial';
        this.ctx.fillText('返回主菜单', canvas.width / 2, menuButtonY + buttonHeight / 2 + 8);

        return {
            restartButton: { buttonX: restartButtonX, buttonY: restartButtonY, buttonWidth, buttonHeight },
            menuButton: { buttonX: menuButtonX, buttonY: menuButtonY, buttonWidth, buttonHeight }
        };
    }
}